package exp2.test2;
import java.util.*;
/**
 * Created by 春旺 on 2017/10/24.
 */
public class MainTree {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入先序表达式：");
        String a = scan.nextLine();
        System.out.println("请输入中序表达式：");
        String b = scan.nextLine();

        ArrayList<String> result1 = new ArrayList<String>();
        StringTokenizer tokenizer = new StringTokenizer(a," ");
        while(tokenizer.hasMoreTokens()) {
            result1.add(tokenizer.nextToken());
        }
        Object pre[] = new Object[result1.size()];
        int i = 0;
        while (result1.size() != 0){
            pre[i] = result1.remove(0);
            i ++;
        }

        ArrayList<String> result2 = new ArrayList<String>();
        StringTokenizer tokenizer1 = new StringTokenizer(b," ");
        while(tokenizer1.hasMoreTokens()) {
            result2.add(tokenizer1.nextToken());
        }
        Object mid[] = new Object[result2.size()];
         i = 0;
        while (result2.size() != 0){
            mid[i] = result2.remove(0);
            i++;
        }

        Object pre1 [] = {"A","B","D","H", "I","E","J", "M", "N", "C", "F", "G", "K" ,"L"};
        Object mid1[] = {"H","D", "I" ,"B", "E", "M", "J" ,"N","A" ,"F" ,"C", "K", "G" ,"L"};
        ComeTree tree = new ComeTree();
        System.out.println("后序遍历为：");
        tree.getBehindOrder(pre1, mid1);
    }

}
